<template>
  <div>
    <el-card>
      <span style="font-size: 30px">用户添加</span>
      <el-form :model="addForm" ref="addForm">
        <el-form-item label="用户名" prop="user_name">
          <el-input v-model="addForm.user_name"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="user_pw">
          <el-input v-model="addForm.user_pw"></el-input>
        </el-form-item>
        <el-form-item label="真实姓名" prop="user_fullname">
          <el-input v-model="addForm.user_fullname"></el-input>
        </el-form-item>
        <el-form-item label="用户头像" prop="face_image">
          <el-input v-model="addForm.face_image"></el-input>
        </el-form-item>
        <el-form-item label="个人介绍" prop="user_text">
          <el-input v-model="addForm.user_text"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="resetForm('addForm')">重置</el-button>
          <el-button type="primary"  @click="addUser">确定</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      addForm: {
        user_name: "",
        user_pw: "",
        user_fullname: "",
        face_image: "",
        user_text: "",
        user_display: 1,
      },
    //   rules:{
    //       user_name:[{ required: true, message: '请输入活动名称', trigger: 'blur'}],
    //       user_pw:[{ required: true, message: '请输入活动名称', trigger: 'blur'}],
    //       user_fullname:[{ required: true, message: '请输入活动名称', trigger: 'blur'}],
    //       face_image:[{ required: true, message: '请输入活动名称', trigger: 'blur'}],
    //       user_text:[{ required: true, message: '请输入活动名称', trigger: 'blur'}],
    //       user_display:[{ required: true, message: '请输入活动名称', trigger: 'blur'}],
    //   }
    };
  },
  methods: {
    resetForm(addForm) {
     
        this.$refs[addForm].resetFields();
    
    },
    async addUser() {
      // window.console.log(JSON.stringify(this.addForm));
      let { data: res } = await this.$axios.post("/user/add", this.addForm);
      window.console.log(res.mate.status); //目标值为200
      if (res.mate.status != 200) return this.$message.error(res.mate.msg);
      this.$message.success(res.mate.msg);
      // this.userData.push(this.addForm) dom节点刷新当前数据
      this.getUserList();
      this.addDialogVisible = false;
    },
  },
};
</script>